package com.tianqu.tms.www.transfer.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.Registry;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.entity.TransferFinanceInfo;

/**
 * @author mufeiyu
 * 
 */
public class CarAcceptTransferDialogInfoAjaxAction extends TmsAjaxAction{
	private Logger logger = Logger.getLogger(CarAcceptTransferDialogInfoAjaxAction.class);
	private static final String SERIAL = "serial";
	@Override
	public void process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws TmsException {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();
		controller.begin();
		String serial = request.getParameter(SERIAL);

		TransferAcceptedInfo transferInfo = TransferAcceptedInfo.getInstance();
		transferInfo = transferInfo.findTransferInfoByBasicCarId(serial);
		Codes code = Codes.getInstance();
		TransferFinanceInfo transferFinance = TransferFinanceInfo.getInstance();
		String businessType = "";

		//业务类型
		String carClass = "";
		if(transferInfo.getCarClass() == 1){
			carClass = "新车上牌";
			businessType = "1";
		}else if(transferInfo.getCarClass() == 2){
			carClass = "二手车过户";
			businessType = "2";
		}
		
		//车架号
		String vin = transferInfo.getVin();
		
		//车牌号码
		String licensePlate = transferInfo.getLicensePlate();
		
		
		//号牌种类
		String cardType = code.getItemValueByItemIdAndItemCode(Codes.PLATE_TYPE, Integer.valueOf(transferInfo.getCy_cardType()));
		
		//流程表缴费
		transferFinance = transferFinance.findFinanceInfoByserial(transferInfo.getSerial());
		String checkPrice = "";
		if(transferFinance == null || StringUtil.isNullOrBlank(transferFinance.getCheckPrcieDate())){
			checkPrice = Registry.getConfigFromDb(TmsConstants.CHECKPRICE);		
		}else {
			checkPrice = "已缴费";
		}
		
		//拼select
		StringBuffer str = new StringBuffer();

		str.append(carClass);//车辆种类	
		str.append("##");
		
		str.append(vin);//车架号
		str.append("##");
		
		str.append(licensePlate);//车牌号码
		str.append("##");
		
		str.append(cardType);//号牌种类
		str.append("##");
			
		if(transferFinance == null || StringUtil.isNullOrBlank(transferFinance.getCheckPrcieDate())){//流程表缴费
			str.append("<input id=\"checkPriceStr\" value=\"" + checkPrice + "\"type=\"text\" class=\"tmsdyInput\"/>");
		}else {
			str.append("<input style=\"background:none;border:0;\" id=\"checkPriceStr\" value=\"" + checkPrice + "\"type=\"text\" class=\"tmsdyInput\" readonly=\"true\" />");	
		}
		str.append("##");
		
		str.append(businessType);
		str.append("##");
		
		if("已缴费".equals(checkPrice)){
			str.append("1");
		}else {
			str.append("0");
		}

		
		String responseText =str.toString();
		controller.commit();
		responseValues(response, responseText, TEXT);
		
		logger.debug(this.getClass().getName() + "#doAction was completed.");
	}

}
